import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  UseGuards,
  Put,
  Query,
} from '@nestjs/common';
import { SettingService } from './setting.service';
import { AuthGuard } from '../../@nt/guards/auth.guard';
import { AdminGuard } from '../../@nt/guards/admin.guard';
import { QueryCandidateDto, SettingDto } from './dto/setting.dto';
import { RestController } from '../../@nt';

// 选举设置控制器
@Controller('setting')
@UseGuards(AuthGuard, AdminGuard)
export class SettingController extends RestController {
  constructor(protected readonly service: SettingService) {
    super(service);
  }

  // 创建投票选举场次设置
  @Post()
  async create(@Body() body: SettingDto): Promise<any> {
    return await this.service.create(body);
  }

  // 根据ID获取投票选举场次设置
  @Get('info/:id')
  async findOne(@Param('id') id: string): Promise<any> {
    return await this.service.findOne(+id);
  }

  // 获取投票选举场次列表
  @Get('list')
  async findAll(@Query() query: QueryCandidateDto): Promise<any> {
    return await this.service.findAll(query);
  }

  // 更新投票选举场次设置
  @Patch(':id')
  async update(
    @Param('id') id: string,
    @Body() body: SettingDto,
  ): Promise<any> {
    return await this.service.update(+id, body);
  }

  // 结束投票场次选举
  @Put(':id')
  async endElection(@Param('id') id: string): Promise<any> {
    return await this.service.endElection(+id);
  }

  // 根据ID获取投票选举数据
  @Get('result/:id')
  async getElectionResult(@Param('id') id: string): Promise<any> {
    return await this.service.getElectionResults(+id);
  }
}
